<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://blogs">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<!-- BLOG BAR -->
	<xsl:template match="object[@type='blog']" mode="blog-bar">
		<xsl:param name="id" select="@id" />
		<xsl:param name="alias" select="property[@name='alias']/value" />
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="allowVote" select="@vote-allow" />
		
		<div id="blog_l">
			<div id="blog_avatar">
				<img>
					<xsl:attribute name="alt">
						<xsl:value-of select="property[@name='title']/value" />
					</xsl:attribute>
					<xsl:attribute name="src">
						<xsl:if test="property[@name='avatar']/value = ''">
							<xsl:value-of select="concat ($baseURI, '/images/default-blog-avatar.png')" />
						</xsl:if>
						<xsl:if test="property[@name='avatar']/value != ''">
							<xsl:value-of select="concat ($baseURI, property[@name='avatar']/value)" />
						</xsl:if>
					</xsl:attribute>
				</img>
			</div>
			<div>
				<xsl:apply-templates select="document(concat('xmodule://system/getVoted/', $rating, ';', $allowVote, ';', @type-id, ';', @id, ';1'))/data/response/vote" mode="blog-vote" />
			</div>
		</div>
		<div id="blog_info_body">
			<h3>
				<xsl:text>&labelBlog; «</xsl:text>
				<a href="{$baseURI}/blog/{$alias}">
					<xsl:value-of select="property[@name='title']/value" />
				</a>
				<xsl:text>» </xsl:text>			
				<xsl:if test="$userGroup != 'guest'">
					<a id="subscribe_blog" href="javascript:void(0)" onclick="subscribeBlog ({@id}); return false;">
						<xsl:if test="@user-member = '1'">
							<xsl:text>&labelLeaveBlog;</xsl:text>		
						</xsl:if>
						<xsl:if test="@user-member = '0'">
							<xsl:text>&labelJoinBlog;</xsl:text>		
						</xsl:if>
					</a>
				</xsl:if>
				<xsl:if test="@admin = '1'">
					<xsl:text> </xsl:text>
					<a href="{$baseURI}/blogs/edit_blog/{@id}" title="&labelEditBlog;">
						<img src="{$baseURI}/images/settings-icon.png" alt="" />
					</a>
				</xsl:if>
			</h3>
			<p>
				<xsl:value-of select="property[@name='description']/value" />
			</p>
			<a href="javascript:void(0);" onclick="showBlogMembers ({$id});" class="link_on_page">&labelShowBlogMembers;</a>
			<div id="blog_members" style="display:none;" />
		</div>
	</xsl:template>
	
	<!-- BLOG OWNER BAR -->
	<xsl:template match="object[@type='user']" mode="personal-blog-bar">
		<xsl:param name="userLogin" select="property[@name='login']/value" />
		
		<div id="blog_owner_bar">
			<div id="owner_avatar">
				<a href="{$baseURI}/user/{$userLogin}">
					<img>
						<xsl:attribute name="src">
							<xsl:if test="property[@name='avatar']/value = ''">
								<xsl:value-of select="concat ($baseURI, '/images/default-avatar.png')" />
							</xsl:if>
							<xsl:if test="property[@name='avatar']/value != ''">
								<xsl:value-of select="concat ($baseURI, '/thumb_50_50', property[@name='avatar']/value)" />
							</xsl:if>						
						</xsl:attribute>
						<xsl:attribute name="alt">
							<xsl:value-of select="property[@name='name']/value" />
						</xsl:attribute>
					</img>
				</a>
			</div>
			<div id="owner_info">
				<h3 id="owner_name">
					<xsl:text>&labelBlogOfUser; </xsl:text>
					<a href="{$baseURI}/user/{$userLogin}">
						<xsl:value-of select="property[@name='name']/value" />
					</a>
				</h3>
				<div>
					<a href="{$baseURI}/user/{$userLogin}">&labelUserProfile;</a>
					<a href="{$baseURI}/blogs/user/{$userLogin}" class="selected">&labelBlog;</a>
					<a href="{$baseURI}/photos/user/{$userLogin}">&labelUserPhotos;</a>
				</div>
			</div>
		</div>
	</xsl:template>
	
	<!-- BLOG VOTE -->
	<xsl:template match="vote" mode="blog-vote">
		<xsl:param name="blogId" select="object_id" />
		<xsl:param name="vote" select="mark" />
		<xsl:param name="allow" select="allow" />
		<xsl:param name="rating" select="rating" />
		
		<div id="blog_rating">
			<a id="blog_vote_plus" href="javascript:void(0);" title="&labelLike;">
				<xsl:choose>
					<xsl:when test="$allow = '0' and $vote = ''">
						<xsl:attribute name="onclick">
							<xsl:text>new Error ('&labelCantVote;');</xsl:text>
						</xsl:attribute>
						<img src="{$baseURI}/images/post-vote-plus-cant.png" alt="" />
					</xsl:when>
					<xsl:when test="$allow = '0' and $vote != ''">
						<xsl:attribute name="onclick">
							<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
						</xsl:attribute>
						<xsl:if test="$vote = '1'">
							<img src="{$baseURI}/images/post-voted-plus.png" alt="" />
						</xsl:if>
						<xsl:if test="$vote != '1'">
							<img src="{$baseURI}/images/post-vote-plus-cant.png" alt="" />
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('voteBlog (', $blogId, ', 1);')" />
						</xsl:attribute>
						<img src="{$baseURI}/images/post-vote-plus.png" alt="" />
					</xsl:otherwise>
				</xsl:choose>
			</a>
			<span class="blog_rating_number" id="blog_rating_number">
				<xsl:value-of select="$rating" />
			</span>
			<a id="blog_vote_minus" href="javascript:void(0);" title="&labelDislike;">
				<xsl:choose>
					<xsl:when test="$allow = '0' and $vote = ''">
						<xsl:attribute name="onclick">
							<xsl:text>new Error ('&labelCantVote;');</xsl:text>
						</xsl:attribute>
						<img src="{$baseURI}/images/post-vote-minus-cant.png" alt="" />
					</xsl:when>
					<xsl:when test="$allow = '0' and $vote != ''">
						<xsl:attribute name="onclick">
							<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
						</xsl:attribute>
						<xsl:if test="$vote = '0'">
							<img src="{$baseURI}/images/post-voted-minus.png" alt="" />
						</xsl:if>
						<xsl:if test="$vote != '0'">
							<img src="{$baseURI}/images/post-vote-minus-cant.png" alt="" />
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('voteBlog (', $blogId, ', 0);')" />
						</xsl:attribute>
						<img src="{$baseURI}/images/post-vote-minus.png" alt="" />
					</xsl:otherwise>
				</xsl:choose>
			</a>
		</div>
	</xsl:template>

</xsl:stylesheet>